package com.tn.wservice;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.tn.bo.Invoice;

public class PaymentDateCalculator {
	/**
	 * Method to calculated expected payment date.
	 * 
	 * @param invoice
	 * @return expected payment date.
	 */
	public static Date getPaymentDate(Invoice invoice) {
		// payment date should be invoice submitted date + payment terms TODO
		int numberOfDays = (int) invoice.getPaymentTerms().getPaymentDays();
		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(invoice.getInvoiceSubmittedDate());

		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);

		cal.add(Calendar.DAY_OF_YEAR, numberOfDays);
		return cal.getTime();
	}
}
